package com.tarena.ebank.biz.entity;

import org.hibernate.HibernateException;
import org.hibernate.Session;

import com.tarena.ebank.util.HbnUtil;

public class Search {

	public static void main(String args[]) {

		Session s = HbnUtil.getSession();
		User user = new User("A006", "Touch");
		Account acct1 = new Account("600", 700.0);
		Account acct2 = new Account("500", 1700.0);
		Account acct3 = new Account("400", 2500.0);
		try {
			user.getAccts().add(acct1); 
			//user.getAccts().add(acct2);
			
			s.beginTransaction(); // 帐户能看到用户的时候，用级联，我们单独存帐户就能够把用户给存了
			s.save(user);
			//s.save(acct1);
			s.getTransaction().commit();
		} catch (HibernateException e) {
			e.printStackTrace();
			s.getTransaction().rollback();
		} finally {
			s.close();
		}
	}

}
